home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / SELECT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-31  |  1.8 KB  |  67 lines

  1. #include "tcclib.h"
  2. #include <dos.h>
  3. #include <stdio.h>
  4. #include <bios.h>
  5. #include <conio.h>
  6. #include <ctype.h>
  7.  
  8. void writevid ( int x, int y, int x2, char *p, int attrib)
  9. {
  10.     union REGS r;
  11.     register int i;
  12.  
  13.     for ( i = x; i<=x2; i++ ) {
  14.         gotoxy (i, y);
  15.         r.h.ah = 9;
  16.         r.h.bh = 0;
  17.         r.x.cx = 1;
  18.         r.h.al = (*p && i != x)? *p++ : ' ';   /* Highlights entire bar */
  19.         r.h.bl = attrib;
  20.         int86 (0x10, &r, &r);
  21.     }
  22. }
  23.  
  24. int select (char *menu[], int items, int x1, int y1, int x2)
  25. {
  26.     union inkey {
  27.         char ch[2];
  28.         int i;
  29.     } c;
  30.     register int arrow = 0, x;
  31.  
  32.     writevid (x1, y1, x2, menu[0], A_REVERSE); /* highlight */
  33.     for (;;) {
  34.         while (!bioskey(1)) continue;
  35.         c.i = bioskey (0);
  36.  
  37.         writevid (x1, y1 + arrow, x2, menu[arrow], A_NORMAL);
  38.  
  39.         if (c.ch[0]) {
  40.             switch (c.ch[0]) {
  41.                 case '\r': return (arrow);
  42.                 case ' ':  ++arrow; break;
  43.                 case 27:   return (-1);
  44.                 default:
  45.                     for ( x = arrow + 1; x != arrow; ++x ) {
  46.                         if ( x == items ) x = -1;
  47.                         else if ( toupper (c.ch[0]) == toupper (menu[x][0]) )
  48.                             arrow = x--;
  49.                     }
  50.                     if ( toupper (c.ch[0]) != toupper (menu[x][0]) )  putc (7, stdout);
  51.                     break;
  52.             }
  53.         }
  54.         else {
  55.             switch (c.ch[1]) {
  56.                 case 72: case 75: --arrow; break;
  57.                 case 80: case 77: ++arrow; break;
  58.                 default: putc (7, stdout); break;
  59.             }
  60.         }
  61.  
  62.         if ( arrow == items ) arrow = 0;
  63.         if ( arrow < 0 ) arrow = items - 1;
  64.         writevid (x1, y1+arrow, x2, menu[arrow], A_REVERSE);
  65.     }
  66. }
  67.